@ControllerAdvice, a new annotation provided by spring3.2, can be seen in the name of the general meaning of controller enhancement. Let us first look at the implementation of @controlleradvice:Java code
@Target (Elementtype.type)
@Retention (Retentionpolicy.runtime)
@Documented
@Component
Public @interface Controlleradvice {
}
Nothing special, the annotations use @com
-5.0.6. Release.jar:5.0.6. RELEASE] at Org.springframework.web.servlet.FrameworkServlet.processRequest (Frameworkservlet.java:974) ~[spring-webmvc-5.0.6. Release.jar:5.0.6. RELEASE] at Org.springframework.web.servlet.FrameworkServlet.doGet (Frameworkservlet.java:866) ~[spring-webmvc-5.0.6. Release.jar:5.0.6. RELEASE] at Javax.servlet.http.HttpServlet.service (Httpservlet.java:635) ~[tomcat-embed-core-8.5. t
Controller responsebody Restcontroller Controlleradvice restcontrolleradvice
@Controller
@Target ({elementtype.type})
@Retention (retentionpolicy.runtime)
@Documented
@Component public
@ Interface Controller {
/**
* The value may indicate a suggestion for a logical component name,
* to be turned into a Spring bean in the case of a autodetected component.
* @return The suggested component
, the other two are not very helpful.Next look at the snippet code:Java code
@ControllerAdvice
Public class Controlleradvicetest {
@ModelAttribute
Public User NewUser () {
System.out.println ("============ applies to all @requestmapping annotation methods and puts the return value into model before it executes");
return new User ();
}
@InitBinder
public void Initbinder (Webdatabinder binder) {
System.out.println ("======
The first step: Dispatcher Front controller of the source code in the defaultPrivate Boolean Throwexceptionifnohandlerfound = False, indicating that if no matching executor is found, no exception is thrown handler not found, so the 404 exception is to be captured if this property is to be changed to TrueYou can use the configuration of Web. XML Dispatcher This parameter is true for specific configuration parameters, please Baidu, here does not elaborateStep Two: Create a new class, add @
First of all. Using Controlleradvice alone does not work correctly. Need to be used in conjunction with @enablewebmvc.@ControllerAdvice@EnableWebMvcPulbic class exceptioncontrolleradvice{ @ExceptionHandler (notfoundexception. class) @ResponseBodyPublic map.......}}Exception handling Error in startup.Error message:July 04, 2016 11:00:11 am org.springframework.web.servlet.mvc.method.annotation.ExceptionH
the uploaded file to be obtained
3.19. Uricomponentsbuilder and uricomponents Spring 3.2-new Features
4.1. Support for Servlet 3 based Asynchronous request processing4.2. Spring MVC Test Framework-First-class support for testing Spring MVC applications with a fluent API and without a Servlet container. Server-side tests involve use the "dispatcherservlet while
When we are doing Web applications, it is very common for errors to occur during request processing. Spring Boot provides a default mapping: When an exception is thrown in processing, it is /error forwarded to the request for processing, and the request has a global error page to display the exception content.Choose a previously implemented web App (Chapter3-1-2) to start the app, access a nonexistent URL, or modify the processing to throw an exceptio
it as a spring bean.@RequestMapping: You can annotate Web requests (access paths and parameters) on classes and methods@RequestMapping (value= "/convert", produces+{"application/x-wisely"}) set the Access URL return value type@ResponseBody: Supports putting the return value into response instead of returning a page (a group of data is returned)@RequestBody: The request parameter is allowed in the request body instead of directly attached to the addre
duplicatespittleexception approach to all the controllers of the entire application. The following list of programs showsAppwideexceptionhandler can accomplish this task, which is a class with @ControllerAdvice annotations.4. Redirect and forwardIn the view name returned by the Controller method, we use the power of the "redirect:" prefix. When the Controller method returns a String value that starts with "redirect:", then this String is not used to
Spring Boot series (iii) Spring boot common annotations
@RestController and @requestmapping
@RestController is called a stereotype (stereotype) annotation. It provides suggestions for developers who read the code. For spring, this class plays a special role. It inherits from @controller annotations. Prior to 4.0, Spring
The spring framework is like a vendor with many products under it, such as spring Boot, spring frame, spring cloud, and so on.Spring boot is designed to quickly, easily, and easily build a spring project. It's fast, easy, and simple because
When we are doing Web applications, it is very common for errors to occur during request processing. Spring Boot provides a default mapping: When an exception is thrown in processing, it is /error forwarded to the request for processing, and the request has a global error page to display the exception content. Springboot default error page effect is as follows:Although the default error mapping is implemented in S
In all previous spring boot and spring cloud related posts, the creation of the spring boot project will be involved. There are many ways to create them, and we can build them either manually or through scaffolding.In this article we will introduce the spring INITIALIZR tool in embedded IntelliJ, which, like the web-pr
classes.Therefore, if you need to define additional components, simply create the appropriate initialization class. The simplest approach is to implement the spring Webapplicationinitializer interface.import javax.servlet.ServletContext;import javax.servlet.ServletException;import javax.servlet.ServletRegistration.Dynamic;import org.springframework.web.WebApplicationInitializer;import com.myapp.MyServlet;public class MyServletInitializer implements W
Spring-servlet.xml Configuration Spring-security.xml Configuration This article is from the Java Technology Blog blog, so be sure to keep this source http://lingdong.blog.51cto.com/3572216/1889448Spring MVC and Spring Security Configuration spring-servlet.xml and Spring-sec
Objective
Learn the simple knowledge ahead Spring Web and then learn the higher-order Web techniques.
Advanced technology substitution Scenarios for spring MVC configuration Custom Dispatcherservlet configurationIn the fifth chapter we have written the following code.public class Spitterwebinitializer extends Abstractannotationconfigdispatcherservletinitializer { @Override classgetrootcon
Spring for cainiao: Spring and spring for cainiao1. concepts.
Spring is an open-source framework. Spring was a lightweight Java development framework that emerged in 2003, it is derived from part of the concepts and prototype stated by Rod Johnson in his book "Expert One-
[51cto] This article is "Hello, osgiSeriesPart 5. Starting from this article, we will introduce the spring dynamic model. Let's take a look at why spring dynamic models are so exciting for developers. These developers haveSpring configurations are very familiar and need to explore osgi's modularity, simple version control, and application Lifecycle Support.
51cto editing recommendations:Osgi introduction an
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.